package com.xsjl.qa.service;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.xsjl.qa.mapper.ProblemMapper;
import com.xsjl.qa.pojo.Problem;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * problem服务层
 * 
 * @author Administrator
 *
 */
@Service
public class ProblemService {

	@Autowired
	private ProblemMapper problemMapper;
	


	/**
	 * 查询全部列表
	 * @return
	 */
	public List<Problem> findAll() {
		return problemMapper.selectList(null);
	}

	
	/**
	 * 条件查询+分页
	 * @param whereMap
	 * @param page
	 * @param size
	 * @return
	 */
	public Page<Problem> findSearch(Map whereMap, int page, int size) {
		Page<Problem> pages = new Page<>(page, size);
		QueryWrapper<Problem> wrapper = new QueryWrapper<>();
		wrapper.allEq(whereMap);
		return problemMapper.selectPage(pages, wrapper);
	}

	
	/**
	 * 条件查询
	 * @param whereMap
	 * @return
	 */
	public List<Problem> findSearch(Map whereMap) {
		QueryWrapper<Problem> wrapper = new QueryWrapper<>();
		wrapper.allEq(whereMap);
		return problemMapper.selectList(wrapper);
	}

	/**
	 * 根据ID查询实体
	 * @param id
	 * @return
	 */
	public Problem findById(String id) {
		return problemMapper.selectById(id);
	}

	/**
	 * 增加
	 * @param problem
	 */
	public void add(Problem problem) {
		problem.setVisits(0L);
		problem.setThumbup(0L);
		problem.setReply(0L);
		problem.setSolve("0");
		problem.setCreatetime(new Date());
		problemMapper.insert(problem);
	}

	/**
	 * 修改
	 * @param problem
	 */
	public void update(Problem problem) {
		problemMapper.updateById(problem);
	}

	/**
	 * 删除
	 * @param id
	 */
	public void deleteById(String id) {
		problemMapper.deleteById(id);
	}


	public Page<Problem> newList(String labelId, int page, int rows) {
		Page<Problem> pages = new Page<>(page, rows);
		return problemMapper.newList(labelId, pages);
	}

	public Page<Problem> hotList(String labelId, int page, int rows) {
		Page<Problem> pages = new Page<>(page, rows);
		QueryWrapper<Problem> wrapper = new QueryWrapper<>();
		return problemMapper.hotList(labelId, pages);
	}

	public Page<Problem> waitList(String labelId, int page, int rows) {
		Page<Problem> pages = new Page<>(page, rows);
		QueryWrapper<Problem> wrapper = new QueryWrapper<>();
		return problemMapper.waitList(labelId, pages);
	}

}
